package com.liuyi.netty.im.lychat.modular.caches;

import com.alicp.jetcache.anno.CacheInvalidate;
import com.alicp.jetcache.anno.CacheUpdate;
import com.alicp.jetcache.anno.Cached;
import com.liuyi.netty.im.lychat.modular.entity.Group;
import com.liuyi.netty.im.lychat.modular.service.IGroupService;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * 群组缓存
 * @author Mr.Fmy
 * @since 2021/12/30
 */
@Service
public class GroupCache {

    @Resource
    @Lazy
    private IGroupService groupService;

    @Cached(name = "Group:", key = "'getById:'+#id")
    public Group getById(String id) {
         return groupService.getById(id);
    }

    @CacheUpdate(name = "Group:", key = "'getById:'+#id", value = "#result")
    public Group updateById(String id) {
        return getById(id);
    }

    @CacheInvalidate(name = "Group:", key = "'getById:'+#id")
    public void removeById(String id) {
    }
}
